// hyb_yl/mysubpages/pages/commevaldetail/commevaldetail.js
var app =getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isshow:true,
    // imgList:[],
    imgList: ["https://img30.360buyimg.com/shaidan/s128x96_jfs/t1/70964/23/4950/84524/5d31e5adE714b6b33/61f5d5c79537a8be.jpg!cc_100x100!q70.dpg.webp",
      "https://img30.360buyimg.com/shaidan/s128x96_jfs/t1/70964/23/4950/84524/5d31e5adE714b6b33/61f5d5c79537a8be.jpg!cc_100x100!q70.dpg.webp",
      "https://img30.360buyimg.com/shaidan/s128x96_jfs/t1/70964/23/4950/84524/5d31e5adE714b6b33/61f5d5c79537a8be.jpg!cc_100x100!q70.dpg.webp"
    ],
    replyList: [
      {
        username: '开发局咖啡',
        userImg: "",
        replyCont: "公开答复开发开放就肯定是妇科萨拉刘大可噢诶诶诶开发",
        replyTime: "2019-11-12"
      },
      {
        username: '开发局咖啡',
        userImg: "",
        replyCont: "公开答复开发开放就肯定是妇科萨拉刘大可噢诶诶诶开发",
        replyTime: "2019-11-12"
      }
    ],
    replycont: '',
    maxLength:72,
  },
  upload:function(){
    var info = this.data.info;
    console.log(info.pl_text.text.length)
    var cont = info.pl_text.text
    var isshow = !this.data.isshow
    var maxLength = this.data.maxLength;
    cont = (cont.length > maxLength && isshow) ? cont.substring(0, maxLength - 3) + "..." : cont;
    this.setData({
      isshow:isshow,
      contShow:cont
    })
 
    
  },
  imgbtn:function(e){
    console.log(e)
    var img = e.currentTarget.dataset.item
    var info = this.data.info
    console.log(info)
    wx.previewImage({
      current: img, // 当前显示图片的http链接
      urls: info.pl_text.pic // 需要预览的图片http链接列表
    })
  },
  replycont: function (e) {
    this.setData({
      replycont: e.detail.value
    })
  },
  send: function () {
    if (this.data.replycont == "") {
      wx.showToast({
        title: '请输入您要回复的内容',
        icon: 'none'
      })
    } else {
      var datatime = times.formatDate(new Date())
      var list = {
        username: 'pl',
        userImg: "",
        replyCont: this.data.replycont,
        replyTime: datatime
      }
      var replyList = this.data.replyList;
      replyList.push(list)
      console.log(datatime)
      this.setData({
        replycont: '',
        replyList: replyList
      })
    }
  },
  onPageScroll: function (e) {
    // console.log(e)
    if (e.scrollTop > 100) {
      this.setData({
        floorstatus: true
      });
    } else {
      this.setData({
        floorstatus: false
      });
    }
  },

  //回到顶部
  goTop: function (e) {  // 一键回到顶部
    if (wx.pageScrollTo) {
      wx.pageScrollTo({
        scrollTop: 0
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var bgc = wx.getStorageSync('color')
    var pl_id = options.pl_id
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    this.setData({
      pl_id: pl_id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getDetailpl()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getDetailpl(){
    var that =this
    var pl_id = that.data.pl_id
    console.log(pl_id)
    app.util.request({
      'url': 'entry/wxapp/Goods.Detailpl',
      data:{
        pl_id: pl_id
      },
      success: function (res) {
        console.log(res)
        that.setData({
          info: res.data
        })
        console.log(that.data.info)
        var info = that.data.info;
        var maxLength = that.data.maxLength
        var contShow = info.pl_text.text.substring(0, maxLength - 3)+"..."
        that.setData({
          contShow:contShow
        })
      }
    })
  }
})